<?php
/*
 * 1626cms 職位相關函數
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
 */
if(!defined('IN_QISHI'))
{
	die('Access Denied!');
}
//獲取職位列表
function get_jobs($offset,$perpage,$get_sql= '')
{
	global $db,$timestamp;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
		$limit=" LIMIT ".$offset.','.$perpage;
	}
	$result = $db->query("SELECT * FROM ".table('jobs')." ".$get_sql." ORDER BY id DESC ".$limit);
	while($row = $db->fetch_array($result))
	{
		$row['jobs_url']=url_rewrite('jobs-show',array('id0'=>$row['id']));
		$row['company_url']=url_rewrite('company',array('id0'=>$row['uid']));
		$row['audit']=get_jobs_audit($row['audit']);
		$row['click']=get_jobs_click($row['id']);
		$row['deadline']=($row['deadline']-$timestamp)>0?date('Y-m-d',$row['deadline']):"<span style=\"color:#FF6600\">已經過期</span>";
		$row_arr[] = $row;
	}
	return $row_arr;
}
//獲取單條職位
function get_jobs_one($id=0)
{
	global $db,$timestamp;
	if (intval($id)!= $id) return false;
	$sql = "select * from ".table('jobs')." where id=".$id;
	$val=$db->getone($sql);
	$val['contents']=get_jobs_contents($id);
	$val['contact']=get_jobs_contact($id);
	$val['deadline_days']=($val['deadline']-$timestamp)>0?"距離截止時間還有<strong style=\"color:#FF0000\">".sub_day($val['deadline'],$timestamp)."</strong>":"<span style=\"color:#FF6600\">目前已經過期</span>";
	return $val;
}
//獲取職位描述
function get_jobs_contents($id)
{
	global $db;
	if (intval($id)!= $id) return false;
	$sql = "select * from ".table('jobs_contents')." where pid=".$id;
	$val=$db->getone($sql);
	return $val['contents'];
}
//獲取職位聯系方式
function get_jobs_contact($id)
{
	global $db;
	if (intval($id)!= $id) return false;
	$sql = "select * from ".table('jobs_contact')." where pid=".$id;
	$val=$db->getone($sql);
	return $val;
}
//刪除職位
function del_jobs($del_id,$uid)
{
	global $db;
	$uidsql=" AND uid='".$uid."'";
	if (!is_array($del_id)) return false;
	$sqlin=implode(",",$del_id);
	if (!is_numeric(str_replace(",","",$sqlin))) return false;
	if (!$db->query("Delete from ".table('jobs')." WHERE id IN (".$sqlin.") ".$uidsql."")) return false;
	if (!$db->query("Delete from ".table('jobs_contact')." WHERE pid IN (".$sqlin.") ")) return false;
	if (!$db->query("Delete from ".table('jobs_contents')." WHERE pid IN (".$sqlin.") ")) return false;
	if (!$db->query("Delete from ".table('jobs_click')." WHERE pid IN (".$sqlin.") ")) return false;
	if (!$db->query("Delete from ".table('hk_jobs_welfare')." WHERE job_id IN (".$sqlin.") ")) return false;
	if (!$db->query("Delete from ".table('jobs_shiftwork')." WHERE job_id IN (".$sqlin.") ")) return false;
	if (!$db->query("Delete from ".table('jobs_attachment')." WHERE job_id IN (".$sqlin.") ")) return false;
	return true;
}
//激活或者屏蔽職位
function activate_jobs($idarr,$display,$uid)
{
	global $db;
	$uidsql=" AND uid='".$uid."'";
	if (!is_array($idarr)) return false;
	if (intval($display)!=$display || intval($uid)!=$uid) return false;
	$sqlin=implode(",",$idarr);
	if (!is_numeric(str_replace(",","",$sqlin))) return false;
	if (!$db->query("update  ".table('jobs')."  SET display='".$display."' WHERE id IN (".$sqlin.") ".$uidsql."")) return false;
	return true;
}
//刷新職位
function refresh_jobs($idarr,$uid)
{
	global $db,$timestamp;
	$uidsql=" AND uid='".$uid."'";
	if (!is_array($idarr)) return false;
	$sqlin=implode(",",$idarr);
	if (!is_numeric(str_replace(",","",$sqlin))) return false;
	if (!$db->query("update  ".table('jobs')."  SET refreshtime='".$timestamp."' WHERE id IN (".$sqlin.") ".$uidsql."")) return false;
	refresh_company($uid);
	return true;
}
//刷新企業
function refresh_company($uid)
{
	global $db,$timestamp;
	$wheresql=" WHERE uid='".intval($uid)."'";
	if (!$db->query("update  ".table('company_profile')."  SET refreshtime='".$timestamp."'  ".$wheresql."")) return false;
	return true;
}
//獲取職位審核狀態
function get_jobs_audit($audit)
{
	switch ($audit)
	{
		case 1:  $audit = "審核通過";  break;
		case 2:  $audit = "審核中···";  break;
		case 3:  $audit = "<span style=\"color:#999999\">審核未通過</span>"; break;
		default:  $audit = "未知";
	}
	return $audit;
}
//獲取職位點擊次數
function get_jobs_click($pid)
{
	global $db;
	$sql = "select * from ".table('jobs_click')." where pid=".$pid;
	$val=$db->getone($sql);
	return $val['click'];
}
//獲取企業資料
function get_company_profile($uid){
	global $db;
	$sql = "select * from ".table('company_profile')." where uid=".$uid;
	$lsit=$db->getone($sql);
	return $lsit;
}
//獲取企業介紹
function get_company_profile_contents($uid){
	global $db;
	$sql = "select * from ".table('company_profile_contents')." where uid=".$uid;
	$lsit=$db->getone($sql);
	return $lsit;
}
?>
